Fix: resolution kwarg silently ignored in RFDETR.train()#933
Merged
Conversation
2 tasks
…ig.resolution Agent-Logs-Url: https://github.com/roboflow/rf-detr/sessions/8cb000ce-15e1-42c1-bd22-2d383e3176de Co-authored-by: Borda <6035284+Borda@users.noreply.github.com>
Agent-Logs-Url: https://github.com/roboflow/rf-detr/sessions/8cb000ce-15e1-42c1-bd22-2d383e3176de Co-authored-by: Borda <6035284+Borda@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix image size not changing with resolution argument
Fix: resolution kwarg silently ignored in RFDETR.train()
Apr 8, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #933 +/- ##
======================================
Coverage 79% 79%
======================================
Files 97 97
Lines 7846 7875 +29
======================================
+ Hits 6195 6224 +29
Misses 1651 1651 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a bug where resolution=... passed to RFDETR.train() was silently ignored because it is a ModelConfig field (not a TrainConfig field), then adds tests to lock in the corrected behavior.
Changes:
- Pop and handle
resolutioninsideRFDETR.train()before callingget_train_config(). - Validate resolution divisibility by
patch_size × num_windows, and update model config fields accordingly. - Add unit tests for resolution override behavior and error cases.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
src/rfdetr/detr.py |
Absorbs resolution in RFDETR.train(), validates it, and mutates model_config before building TrainConfig. |
tests/training/test_detr_shim.py |
Adds tests ensuring the resolution kwarg is popped, applied to the model config, and invalid values raise. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
- [resolve C1] use operator.index() to normalize resolution type; explicitly reject bool, non-positive, and non-integer values before divisibility check - [resolve C2/OptionB] only update positional_encoding_size when the config currently derives it formulaically (PE == resolution // patch_size); RFDETRBase keeps its pretrained DINOv2 PE=37 unchanged to preserve checkpoint compatibility - [resolve C4] reword docstring to describe Option B PE behaviour and persistent model_config mutation - [resolve C5] replace Unicode × with ASCII * in error message for terminal/log-parser compatibility --- Co-authored-by: Claude Code <noreply@anthropic.com>
- [resolve C6] keep Base PE test aligned with Option B (DINOv2 PE preserved) - [resolve R3] add test_resolution_kwarg_updates_positional_encoding_size_for_formula_derived_config using RFDETRSmallConfig to verify PE IS updated for formula-derived configs - [resolve R2] parametrize 7 invalid inputs (zero, negative, bools, floats, string) against new ValueError guard - [resolve R4] replace hardcoded resolution literals with computed block_size * N so tests self-document config constraints --- Co-authored-by: Claude Code <noreply@anthropic.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…case literals - Removed redundant type and value checks for resolution. - Updated test cases to use a more distinct `valid_resolution` value (`block_size * 11`) for clarity.
…github.com/roboflow/rf-detr into copilot/fix-image-size-resolution-argument
Borda
approved these changes
Apr 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TrainConfigextends plainBaseModel(extra fields ignored), so passingresolution=Nto.train()was silently dropped — the model always trained at the default config resolution regardless of what the user set.Changes
RFDETR.train()now absorbsresolutionbefore forwarding remaining kwargs toget_train_config():patch_size × num_windows(raisesValueErrorif not)self.model_config.resolutionpositional_encoding_sizeonly when the current config is formula-derived (PE == resolution // patch_size); pretrained-specific PE values are preservedresolutionas a first-class.train()kwargUsage
Invalid resolutions raise immediately with a clear message:
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
https://storage.googleapis.com/rfdetr/nano_coco/checkpoint_best_regular.pth/usr/bin/python python -m pytest tests/training/ src/ -x -v -m not gpu --ignore=tests/training/test_metrics_csv.py(http block)/usr/bin/python python -m pytest src/rfdetr/detr.py::rfdetr.detr.RFDETR.optimize_for_inference -v(http block)/usr/bin/python python -m pytest src/rfdetr/detr.py::rfdetr.detr.RFDETR.optimize_for_inference -v --tb=short(http block)https://storage.googleapis.com/rfdetr/rf-detr-seg-n-ft.pth/usr/bin/python python -m pytest tests/ src/ -v -m not gpu --ignore=tests/training/test_metrics_csv.py --ignore=src/rfdetr/detr.py --ignore=tests/try_instantiate_all_models.py(http block)huggingface.co/usr/bin/python python -m pytest tests/ src/ -v -m not gpu --ignore=tests/training/test_metrics_csv.py --ignore=src/rfdetr/detr.py --ignore=tests/try_instantiate_all_models.py(dns block)images.cocodataset.org/usr/bin/python python -m pytest tests/ src/ -v -m not gpu --ignore=tests/training/test_metrics_csv.py --ignore=src/rfdetr/detr.py --ignore=tests/try_instantiate_all_models.py(dns block)If you need me to access, download, or install something from one of these locations, you can either: